<?php
namespace Product\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Insert;
use Zend\Db\Sql\Update;
use Zend\Db\Sql\Delete;

class ProductTable extends AbstractTableGateway
{
    protected $table = 'zz_index';
	

    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
    }

    public function fetchAll()
    {
        $resultSet = $this->select(function (Select $select) {
                    $select->order('name ASC');
                });
        $entities = array();
        foreach ($resultSet as $row) {
            $entity = new Entity\Coba();
            $entity->setName($row->Name)
                   ->setQuantity($row->Quantity)
                   ->setOwner($row->Owner);
            $entities[] = $entity;
        }
        return $entities;
    }
	
	public function getProduct($id)
    {
        $id  = (int) $id;
        $rowset = $this->tableGateway->select(array('id' => $id));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $id");
        }
        return $row;
    }
	
}
?>